class Api::ProductsController < Api::BaseController

  def index
    if params[:category_id]
      @products = Category.find(params[:category_id]).products
    else
      @products = Product.all
    end
    items = @products.map{|p| p.summary_builder}
    api_success(message: '', data: {items: items})
  end

  def show
    @product = Product.find_by(id: params[:id])
    if @product
      api_success(data: {product: @product.detail_builder})
    else
      api_error
    end
  end

end
